#define _CRT_SECURE_NO_WARNINGS
#pragma once
#include <stdio.h>
#include <malloc.h>
#include <assert.h>
#include <memory.h>
#include <stdlib.h>
#include <iostream>
#include <stack>
using namespace std;

#define ElemType int
#define P 7
#define NULL_DATA -1

typedef struct bucket_node {
	ElemType data[3];
	struct bucket_node *next;
}bucket_node;

bucket_node hash_table[P];


void init_bucket_node() {
	for (int i = 0; i < P; i++) {
		for (int j = 0; j < 3; j++) {
			hash_table[i].data[j] = NULL_DATA;
		}
		hash_table[i].next = NULL;
	}
}

int Hash(int key) { return key % P; }
bool insert_new_element(int x) {
	int index = Hash(x);
	for (int i = 0; i < 3; i++) {
		if (hash_table[index].data[i] == NULL_DATA) {
			hash_table[index].data[i] = x;
			return true;
		}
	}

	bucket_node *p = hash_table[index].next;
	while (p->next != NULL) {
		p = p->next;
		for (int i = 0; i < 3; i++) {
			if (p->data[i] == NULL_DATA) {
				p->data[i] = x;
				return true;
			}
		}
	}

	bucket_node *s = (bucket_node*)malloc(sizeof(bucket_node));
	assert(s != NULL);
	for (int i = 0; i < 3; i++) {
		s->data[i] = NULL_DATA;
	}
	s->next = NULL;
	s->data[1] = x;
	p->next = s;
	return true;
}